<?php
defined('BASEPATH') OR exit('No direct script access allowed');


use QCloud_WeApp_SDK\Mysql\Mysql as DB;



class ProductDetail extends CI_Controller {
    public function index() {
        $pid = $_GET['pid'];
        $userid = $_GET['userid'];
        $rows = null;
        if($pid){
            $rows = DB::row('cc_goods',['*'], ['id' => $pid]);
            if($rows){
                $coupon = DB::row('cc_coupon',['*'], ['pid' => $pid,'userid' => $userid]);
                if($coupon){
                    $rows->has_coupon = $coupon->has_coupon;
                    $rows->coupon_id = $coupon->coupon_id;
                    $rows->userid = $coupon->userid;
                }else{
                    $rows->has_coupon = 0;
                    $rows->userid = $userid;
                }

            }
        }

        if (!empty($rows)){
            $this->json([
                'code' => 0,
                'data' => $rows
            ]);
        } else {
            $this->json([
                'code' => -1,
                'error' => $rows['error']
            ]);
        }
    }
}
